<template>
	<view>
		<view class="selectPicker">
			<view class="selectPicker-value">
				{{ selectName }}
			</view>
			<up-icon name="arrow-down" size="18" color="#999" @click="handleOpen"></up-icon>
		</view>
		<up-popup :show="dialogShow" :closeable="true" @close="onCancel">
			<scroll-view scroll-y="true" class="dialogMain">
				<view v-for="(item,index) in selectDatas" :key="index" class="dialog-scroll-item" :class="{'active':activeId===item.id}"  @click="onSelectCurrent(item,index)">
					{{item.name}}
				</view>
			</scroll-view>
		</up-popup>
	</view>
</template>
<script>
	export default {
		props: {
			selectInfo: {
				type: Object,
				default: ()=>{}
			},
			columns: {
				type: Array,
				default: () => []
			},
			labelName: {
				type: String,
				default: 'name'
			}
		},
		emits: ['select'],
		data() {
			return {
				selectName:"",
				dialogShow: false,
				activeId: '',
				selectDatas: [],
				indicatorStyle: `height: 50px;`,
				value:[]
			}
		},
		watch:{
			columns(newVal){
				this.selectDatas=newVal;
			},
			selectInfo(info){
				this.selectName=info.name;
				this.activeId=info.id;
			}
		},
		methods: {
			handleOpen() {
				this.dialogShow = true;
			},
			onSelectCurrent(item,index) {
				this.activeId = item.id;
				this.$emit('select',item);
				this.dialogShow=false;
			},
			onCancel() {
				this.dialogShow = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.selectPicker {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		width: 100%;

		&-value {
			height: 42rpx;
			flex: 1;
			margin-right: 15rpx;
			max-width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	}
	.dialogMain {
		max-height: 50vh;
		min-height: 100rpx;
		padding:40rpx 20rpx 20rpx 20rpx;
		.dialog-scroll-item {
			padding: 16rpx 0;
			font-size:30rpx;
			text-align: center;
			&.active {
				color:#00b277;
				font-weight: bold;
			}
		}
	}
</style>